import java.util.*;

/**
 * @Author 12629
 * @Date 2022/3/26 8:25
 * @Description：
 */

class Card implements Comparable<Card> {
    public int rank; // 数值
    public String suit; // 花色
    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }
    @Override
    public int compareTo(Card o) {
        if (o == null) {
            return 1;
        }
        return this.rank -o.rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Card card = (Card) o;
        return rank == card.rank && this.suit.equals(card.suit);
    }

    /*@Override
    public int hashCode() {
        return Objects.hash(rank, suit);
    }*/
}

class RankComparator implements Comparator<Card> {

    @Override
    public int compare(Card o1, Card o2) {
        return o2.rank-o1.rank;
    }
}


public class TestDemo {

    public static void main111(String[] args) {
        Card card1 = new Card(5,"梅花");
        Card card2= new Card(5,"梅花");
        System.out.println(card1.equals(card2));


       /* Card card3 = card1;
        System.out.println(card1.equals(null));*/
    }

    public static void main4(String[] args) {
        Card card1 = new Card(13,"红桃");
        Card card2= new Card(5,"梅花");

        System.out.println(card1.compareTo(card2));

        RankComparator rankComparator = new RankComparator();
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>(rankComparator);
        priorityQueue.offer(card1);
        priorityQueue.offer(card2);

        Card card = priorityQueue.peek();
        System.out.println(card);

    }

    public int[] smallestK(int[] array, int k) {
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        //PriorityQueue<Integer> maxHeap2 = new PriorityQueue<>(k,((o1, o2) -> {return o2-o1;}));


        for(int i = 0;i < k;i++) {
            maxHeap.offer(array[i]);
        }

        // 0 <= k <= len
        for (int i = k; i < array.length; i++) {
            //1、先获取堆顶元素
            if(maxHeap.peek() != null) {
                int top = maxHeap.peek().intValue();
                if (top > array[i]) {
                    maxHeap.poll();
                    maxHeap.offer(array[i]);
                }
            }
        }

        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = maxHeap.poll();
        }
        return ret;
    }

    public static void main2(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(null);
    }
    public static void main1(String[] args) {
        //默认是小堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        priorityQueue.offer(10);
        priorityQueue.offer(90);
        priorityQueue.offer(3);
        priorityQueue.offer(67);

        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
    }
}
